package com.itheima.controller;


import com.itheima.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserController {
   @RequestMapping("toJumpPage")
    public String toJumpPage() {
       System.out.println("跳转页面");
       return "page.jsp";
   }

    @RequestMapping("toText")
    @ResponseBody
    public String toText() {
        System.out.println("返回纯文本数据");
        return "response text";
    }

    @RequestMapping("toJsonPOJO")
    @ResponseBody
    public User toJsonPOJO() {
        System.out.println("返回json对象数据");
        User user = new User();
        user.setName("a");
        user.setAge(15);
        return user;
    }

    @RequestMapping("toJsonList")
    @ResponseBody
    public List<User> toJsonLIst() {
        System.out.println("返回json集合数据");
        User user1 = new User();
        user1.setName("a");
        user1.setAge(15);

        User user2 = new User();
        user2.setName("b");
        user2.setAge(17);

        User user3 = new User();
        user3.setName("c");
        user3.setAge(19);

        List<User> userList = new ArrayList<User>();
        userList.add(user1);
        userList.add(user2);
        userList.add(user3);

        return userList;
    }



}
